package com.ctgu.rabbitmq.rabbitmq.delayQueue.delayPlugin;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @ ClassName DelayPluginConfig
 * @ Author Alex2
 * @ Date 2025/8/15 15:54
 **/
@Configuration
public class DelayPluginConfig {
    public static final String DLX_EXCHANGE_DELAY_PLUGIN = "dlx_exchange_delay_plugin";
    public static final String DLX_QUEUE_DELAY_PLUGIN = "dlx_queue_delay_plugin";
    public static final String DLX_ROUTING_KEY_DELAY_PLUGIN = "dlx_routing_key_delay_plugin";

    @Bean
    public CustomExchange delayPluginExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct"); // 基于 direct 类型
        return new CustomExchange(DLX_EXCHANGE_DELAY_PLUGIN, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue delayPluginQueue() {
        return QueueBuilder.durable(DLX_QUEUE_DELAY_PLUGIN).build();
    }

    @Bean
    public Binding delayPluginBinding() {
        return BindingBuilder.bind(delayPluginQueue())
                .to(delayPluginExchange())
                .with(DLX_ROUTING_KEY_DELAY_PLUGIN).noargs();
    }
}